package com.dylan.datacollection.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.bumptech.glide.Glide;
import com.dylan.datacollection.R;
import com.dylan.datacollection.entity.MsgEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Vito's Pc on 2016/9/18 0018.
 */
public class MsgListAdapter extends BaseAdapter {
    private List<MsgEntity> mDatas = null;
    private Context mContext = null;
    private int mMsgType = 0;
    public MsgListAdapter(int msgType, Context context, List<MsgEntity> datas ){
        mContext = context;
        mMsgType = msgType;
        if ( null == mDatas ){
            mDatas = new ArrayList<>();
        }
        mDatas.addAll(datas);
    }

    public void setmDatas(List<MsgEntity> mDatas, int msgType) {
        this.mDatas = mDatas;
        this.mMsgType = msgType;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public MsgEntity getItem(int position) {
        return mDatas == null ? null : mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mDatas == null ? 0 : position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if ( null == convertView ){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_msg_list,null);
            holder = new Holder();
            holder.titleNameTextView = (TextView) convertView.findViewById(R.id.item_msg_name_text_view);
//            holder.timeTextView = (TextView) convertView.findViewById(R.id.item_msg_time_text_view);
            holder.contentTextView = (TextView) convertView.findViewById(R.id.item_msg_content_text_view);
//            holder.imgView = (ImageView) convertView.findViewById(R.id.item_msg_img_imageView);
            convertView.setTag(holder);
        }else {
            holder = (Holder) convertView.getTag();
        }
        MsgEntity itemBean = getItem(position);
//        if (!TextUtils.isEmpty(itemBean.getImg())){
//            holder.imgView.setVisibility(View.VISIBLE);
//            Glide.with(mContext).load(itemBean.getImg()).placeholder(R.mipmap.ic_default).thumbnail(0.1f).error(R.mipmap.ic_default).skipMemoryCache(false).into(holder.imgView);
//
//        }else{
//            holder.imgView.setVisibility(View.GONE);
//        }
        holder.contentTextView.setText(itemBean.getSummary());
        holder.titleNameTextView.setText(itemBean.getTitle());
//        holder.timeTextView.setText(itemBean.getUpdated_date());
        return convertView;
    }

    class Holder{
        TextView titleNameTextView = null,timeTextView = null,contentTextView = null,moneyTitleTextView = null, moneyCountTextView = null, checkMoreTextView = null;
        ImageView imgView;
    }

}
